home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Various / DevDisk 65 (1989)(DevWare PD).zip / DevDisk 65 (1989)(DevWare PD).adf / prosuite / fileio.doc < prev    next >
Text File  |  1990-07-11  |  40KB  |  1,028 lines

  1.  
  2. FileIO Requester
  3. User and Programmer Manual
  4. From the Amiga Programmer's Suite Book 1, by RJ Mical
  5. Copyright (C) 1987, Robert J. Mical
  6.  
  7.  
  8.  
  9.  
  10. This document describes the FileIO Requester, both for users of
  11. the requester and for programmers who will create the requester.
  12. The main sections of this document are:
  13.  
  14.     o  FROM THE USER'S POINT OF VIEW
  15.  
  16.     o  PROGRAMMER'S REFERENCE
  17.  
  18.     o  DEMO PROGRAM NOTES
  19.  
  20.     o  TECHNICAL REFERENCE
  21.  
  22.     o  USING THE AMIGA PROGRAMMER'S SUITE
  23.  
  24.     o  APPENDIX A:  FileIO Function Calls
  25.  
  26.  
  27.  
  28.  
  29. ============================================================================
  30. === FROM THE USER'S POINT OF VIEW ==========================================
  31. ============================================================================
  32.  
  33. This section presents the FileIO Requester from the user's point of view.  
  34. This is a rough example of the sort of documentation that might be supplied 
  35. to the end user of this FileIO Requester.  
  36.  
  37.  
  38.  
  39. === Welcome to the FileIO Requester ========================================
  40.  
  41. The FileIO Requester allows you an easy way to select which file you want 
  42. to use for input or output.  This section describes how you go about using 
  43. the FileIO Requester.  
  44.  
  45. The FileIO Requester consists of several parts:  
  46.  
  47.     o  the "Select a Name" gadgets which allow you to choose a file name
  48.        simply by scrolling through a list of names until you find the one
  49.        you want, pointing at the name and clicking the left mouse button
  50.  
  51.     o  the OK! gadget which you use to acknowledge that the name you've 
  52.        chosen is the one you wanted
  53.  
  54.     o  3 string gadgets which allow you to type in the name directly 
  55.        rather than using the "Select a Name" gadgets to find the file you 
  56.        want 
  57.  
  58.     o  a NEXT DISK gadget which allows you to examine one disk after 
  59.        another 
  60.  
  61.     o  the CANCEL gadget, which you use to when you've decided you don't 
  62.        want to select a file after all
  63.  
  64.  
  65. The "Select a Name" gadgets present you with a list of file names and allow 
  66. you to use the mouse to scan easily through the list and select one of 
  67. the filenames simply by pointing at it and clicking.  
  68.  
  69. The "Select a Name" gadgets consist of:  
  70.  
  71.     o  a box of where some of the list of file names are displayed
  72.  
  73.     o  a slider which lets you scan quickly through the list of files
  74.  
  75.     o  an up gadget and a down gadget which allow you to move through the
  76.        file list one name at a time
  77.  
  78.  
  79. There are 3 types of entries in the list of file names.
  80.  
  81. At the top of the list are the file names that you can choose.  These 
  82. names are listed in alphabetical order.  
  83.  
  84. At the bottom of the list there are special entries which allow you to move 
  85. around through the drawers of a disk, much like you move around through 
  86. drawers on the Workbench display.  
  87.  
  88. The entries that start with the ">>>>" characters allow you to "open" a 
  89. drawer and examine the names of the files in that drawer.  For example, 
  90. when examining a Workbench disk, at the bottom of the list you would find 
  91. an entry that looked like ">>>> Demos" which means that you can go into 
  92. the drawer named "Demos".  If you selected ">>>> Demos" you would see, 
  93. after a short pause, a new list of file names:  the names of the files 
  94. that are in the "Demos" drawer.  
  95.  
  96. In the "Demos" drawer you would also find a special entry, 
  97. "<<<< PRIOR DRAWER".  If you select this entry, you will move back to 
  98. the drawer that contained your current drawer.  
  99.  
  100. An alternate way to change drawers is to type the name of the drawer you 
  101. want in the string gadget labelled "Drawer" and located to the right of 
  102. the "Select a Name" gadgets.  You select the gadget, type in the name, 
  103. and hit return. 
  104.  
  105. Once you have a list of file names to choose from in the file name box, 
  106. there's a slider gadget to help you scroll around through the names.  
  107. The slider is to the right of the file names.  It has a knob which you 
  108. move to scroll through the names.  The knob will be different sizes 
  109. depending on the number of names in the file list.  If the knob is small, 
  110. this means that you can see only a small number of the total file names.  
  111. The smaller the knob, the more names there are to see.  On the other hand, 
  112. if you can see all the names in the list, the knob will fill up the 
  113. entire slider and you won't be able to move it.  
  114.  
  115. To view the file names, you "grab" the slider's knob and move it up and down.  
  116. You grab the knob by pointing at it and pressing and holding the left mouse 
  117. button.  When you have grabbed the knob, you can move the pointer and 
  118. scan quickly through the list of file names.  
  119.  
  120. Also, you can view the list of names one page at a time by clicking in the 
  121. area of the slider outside of the knob.  If you want fine control of your 
  122. movement through the file list, the up and down gadgets let you adjust 
  123. the list of names one name at a time.  
  124.  
  125. Once you have found the file name that you want to choose, you select it 
  126. by pointing at it and clicking.  When you do this, the name will be 
  127. highlighted and it will appear in a box to the right of the "Select a Name" 
  128. gadgets.  When you've decided that this is really the name you wanted 
  129. to choose, pick the OK! gadget.  Another way to tell the program that 
  130. you're sure you want to select a certain file name is by double-clicking 
  131. on the file name in the same way that you double-click on a Workbench 
  132. icon.  Double-clicking is exactly the same as selecting a name and 
  133. then OK!  
  134.  
  135. If you don't want to use the "Select a Name" gadgets, you can select a 
  136. name by typing the name into the string gadget labelled "Or Type a Name" 
  137. and then hitting return or clicking on the OK! gadget.  Hitting return 
  138. after typing the name you want is the same as selecting OK!  
  139.  
  140. If you know what file name you want and you intend on typing it into 
  141. the string gadget, you can start typing as soon as the requester 
  142. appears.  You don't have to select the string gadget before you start 
  143. typing, and you don't have to wait for the wait pointer to change before 
  144. you hit return!  
  145.  
  146. To view the files of a different disk, select the NEXT DISK gadget.  
  147. When you do, the name of the next disk is displayed in the Disk 
  148. string gadget and the disk is then searched.  If this disk isn't the 
  149. one you wanted, you can press NEXT DISK again even though you may be 
  150. seeing the wait pointer.  You can press NEXT DISK as many times as 
  151. you want until you see the name of the disk you want in the Disk gadget.  
  152. You can also type the name of the disk you want directly into the 
  153. Disk string gadget if you like.  
  154.  
  155. You might notice that the ZZZ-cloud wait pointer looks a little different 
  156. from ones you're used to on the Amiga.  The File IO Requester's ZZZ-cloud 
  157. pointer has a small tab at the top left which allows you to continue 
  158. pointing and making selections even though the ZZZ-cloud is displayed.  
  159. The File IO Requester's ZZZ-cloud tells you that it's working, but it 
  160. doesn't make you wait.  
  161.  
  162. You might notice also that the file names start appearing one by one 
  163. in the Select a Name gadget.  You can select one of these names even 
  164. before all of the names have been added to the list, though this can be 
  165. a bit tricky as they move around a lot.  While the list is being built 
  166. you can use the slider to look at what names have already been added.  
  167. If you see the name that you want to select, you can stop the building 
  168. of the file name list by clicking on a spot inside the requester but 
  169. outside of all the gadgets; for instance, if you click between the 
  170. OK! and CANCEL gadgets this will stop the list from being constructed.  
  171. Then you can select the name you want as usual.  To restart the building 
  172. of the file name list, click on either the Drawer or Disk string gadget 
  173. and hit return.  
  174.  
  175.  
  176.  
  177.  
  178. =============================================================================
  179. === PROGRAMMER'S REFERENCE ==================================================
  180. =============================================================================
  181.  
  182. This section is for the programmer who wants to use the FileIO Requester 
  183. routines in her or his program.  Also, it's an introduction for those who 
  184. intend in delving into the guts of these routines.  For an overview of the 
  185. FileIO Requester routines, refer to the TECHNICAL REFERENCE section.  
  186.  
  187. The Workbench names for DOS objects have been used in the FileIO Requester, 
  188. and are used throughout this document for simplicity.  For your reference, 
  189. a directory is referred to as a "drawer" and volumes, or DOS filesystem 
  190. devices, are referred to as "disks".  
  191.  
  192. The phraseology on the requester itself was left vague intentionally 
  193. so that the same requester could be used to select names for both 
  194. input and output.  
  195.  
  196. These are the subsections of this section:
  197.  
  198.     o  Basic Operation
  199.  
  200.     o  Multiple FileIOSupport Structures
  201.  
  202.     o  Workbench-style Filename Operations
  203.  
  204.     o  If You Don't Want Workbench-style Filename Operations
  205.  
  206.     o  FileIOSupport Flags
  207.  
  208.     o  GetFileIOName() is non-reentrant
  209.  
  210.     o  Procedure for Adding the FileIO Requester to Your Program
  211.  
  212.  
  213.  
  214.  
  215. === Basic Operation ========================================================
  216.  
  217. The FileIO routines base all of their work on a data structure called 
  218. the FileIOSupport structure.  You are allocated one of these structures 
  219. when you call the GetFileIOSupport() routine.  The structure is 
  220. initialized with reasonable default values for you.
  221.  
  222.  
  223. The FileIOSupport structure is used when calling the GetFileIOName() 
  224. routine, which is the routine that actually presents the requester to 
  225. the user and gets the user's filename selection.  
  226.  
  227. There are several flags and data fields in the FileIOSupport structure 
  228. that you may choose to initialize before calling GetFileIOName().  
  229. By setting or clearing these flags, you define how information is 
  230. to be presented to the user of your requester.  These flags are 
  231. described below in "FileIOSupport Flags".  
  232.  
  233. Also, you may choose to give a title to your FileIO requester, which 
  234. title can illuminate the function of the requester.  For instance, 
  235. you may want to have one FileIOSupport structure used for input and 
  236. another for output.  You could give one the title "- SELECT INPUT FILE -" 
  237. and the other "- SELECT OUTPUT FILE -".  The title you supply is 
  238. centered at the top of the requester.  You supply a title by setting 
  239. the ReqTitle field of your FileIOSupport structure to point to 
  240. a null-terminated text string.  You can also set this field to NULL, 
  241. which is the default.  If this field is NULL, a default title is 
  242. displayed.
  243.  
  244. The GetFileIOName() function returns a BOOL value of TRUE or FALSE, 
  245. depending on whether the user completed or cancelled the filename 
  246. selection process.  If the return value is TRUE, you can find the 
  247. filename selected by the user in the FileName[] field of your 
  248. FileIOSupport structure.  The pathname to the file can be constructed 
  249. by calling the BuildFileIOPathname() function or by using the DiskName[] 
  250. and DrawerName[] fields.  
  251.  
  252. You can call GetFileIOName() any number of times with the same FileIOSupport 
  253. structure.  The data in the FileIOSupport structure usually remains 
  254. valid between calls to GetFileIOName(), so with subsequent calls the 
  255. filename list doesn't have to be constructed anew.  This allows the 
  256. requester to appear very quickly because the usually-lengthy process 
  257. of accessing the disk is avoided.  
  258.  
  259. The GetFileIOName() routine uses the GOOD_FILENAMES flag to discern 
  260. whether the data contained in your FileIOSupport structure is valid.  
  261. If GetFileIOName() sees that the flag is not set it builds the filename 
  262. list from scratch.  If the GOOD_FILENAMES is set, the list is not 
  263. recreated.  
  264.  
  265. When GetFileIOSupport() creates a support structure for you, this flag 
  266. is cleared to specify that the support structure doesn't contain good 
  267. filenames.  Thus the first call to GetFileIOName() causes the filename 
  268. list to be constructed.  The GetFileIOName() function normally sets this 
  269. flag (unless the user has done something unusual or if GetFileIOName() 
  270. failed for some reason such as "out of memory"), so that subsequent 
  271. calls to GetFileIOName() work much more efficiently.  
  272.  
  273. But you must do a bit work to support this efficiency.  You are obliged 
  274. to watch for IDCMP events of class DISKINSERTED and to clear the 
  275. GOOD_FILENAMES flag in any of your FileIOSupport structures whenever 
  276. you see this event.  The DISKINSERTED event occurs when the user has 
  277. switched around the disks.  When the user has changed disks you can't 
  278. be sure that your FileIO filename list is still valid, so as a courtesy 
  279. to the user you must cause the filename list to be reconstructed.  
  280.  
  281. You can use the FileIO Requester to get the name of a file to be used 
  282. for output.  If you do and the specified file doesn't currently 
  283. exist, AmigaDOS will create it anew when you open it.  From the 
  284. FileIO Requester point of view, this means that a file now exists 
  285. that isn't in your FileIOSupport list.  To get the name in the list, 
  286. you can use the AddFileIOName() routine.  This routine adds a file 
  287. name to the list of file names currently in the specified 
  288. FileIOSupport structure.  The next time the FileIOSupport structure 
  289. is used for a call to GetFileIOName(), the new file name will apppear 
  290. alphabetized in with the other file names.  If the name is already in 
  291. the list when you call AddFileIOName() then nothing happens.  
  292. This allows you to call AddFileIOName() without worrying about 
  293. duplicate name redundancy, so you can skip checking whether or not 
  294. AmigaDOS has created a new file.  
  295.  
  296. Finally, when you're finished with your FileIOSupport structure (usually 
  297. not until your program is terminating) then you call ReleaseFileIO() to 
  298. deallocate the structure and all the resources that it's accumulated.  
  299.  
  300.  
  301.  
  302. === Multiple FileIOSupport Structures =======================================
  303.  
  304. Your program can have more than one FileIOSupport structure at a time.  
  305. An example of why you would want more than one FileIOSupport structure:  
  306. you might want to have separate structures for getting input filenames 
  307. and output filenames from the user.  Another example:  you might have 
  308. one structure for letting the user select text files and another for 
  309. the selection of graphics files.  
  310.  
  311. If you have more than one FileIOSupport structure, remember that you must 
  312. clear the GOOD_FILENAMES flag in all of them whenever you see Intuition's 
  313. DISKINSERTED IDCMP event class.  
  314.  
  315. Also, regarding new disks, there's an extra procedure that you must follow.  
  316. If the user changes the disk while you've called GetFileIOName(), you 
  317. won't actually see a DISKINSERTED event (as the event will have been 
  318. processed by GetFileIOName() before control is returned to you).  
  319. So how will you know to clear the GOOD_FILENAMES flag in your other 
  320. structures?   Well, GetFileIOName() records the fact that a DISKINSERTED 
  321. event was handled by setting the DISK_HAS_CHANGED flag in your 
  322. FileIOSupport structure.  So on return from a call to GetFileIOName() 
  323. you should check to see whether your FileIOSupport structure has the 
  324. DISK_HAS_CHANGED flag set.  If it does, you should clear the 
  325. DISK_HAS_CHANGED flag in the structure and then clear the GOOD_FILENAMES 
  326. flag in all of your other FileIOSupport structures.  This assures that 
  327. when you call GetFileIOName() with any of your other support structures, 
  328. the filename lists will be reconstructed, as they should.  
  329.  
  330.  
  331.  
  332. === Workbench-style Filename Operations =====================================
  333.  
  334. You can have file names appear in the FileIO Requester using the same 
  335. rules that govern how files appear on the Workbench display, by using 
  336. the Workbench .info file mechanism.  
  337.  
  338. If you intend on using Workbench pattern matching (or if you are going 
  339. to give the user the option) you must make sure that the constant 
  340. WBENCH_CODE is defined in the fileio.h file.  This includes the Workbench 
  341. code in the FileIO files when they are being compiled.  To attempt to 
  342. match Workbench patterns at run time, you must set the WBENCH_MATCH flag 
  343. in your FileIOSupport structure, as described below.  
  344.  
  345. (By the way, if you don't intend on using Workbench-style pattern 
  346. matching and are interested in saving about 500 bytes of code size, 
  347. make sure you comment out the WBENCH_CODE definition.)
  348.  
  349. The Workbench .info file mechanism is a detailed topic that will not be 
  350. delved into here.  Please read the Amiga ROM Kernel Manual for a 
  351. description of the Workbench operation and data types.  What follows is a 
  352. cursory description of the Workbench technique, which is described only 
  353. well enough to explain how you can interact with it via your FileIOSupport 
  354. structure.  
  355.  
  356. The Workbench program examines the directory of a disk and displays 
  357. icons for the files it finds that end with a ".info" suffix (hereafter 
  358. referred to as .info files).  The file names displayed beneath the 
  359. icons have the ".info" suffix removed.  The Workbench .info files 
  360. contain information regarding what type of data is contained in the 
  361. file (executable program, project data, et cetera).  
  362.  
  363. You can choose to have only .info files displayed to the user (with 
  364. the ".info" suffix removed) in the same way that the Workbench does.  
  365. You get this by setting the WBENCH_MATCH flag.  
  366.  
  367. You can further filter the names that appear if you wish.  There are 
  368. two techniques that you can employ for filtering which file names will 
  369. be added to the list:  you can ask for only those files that match a 
  370. particular Workbench object type and only those files that match a 
  371. particular tool type.  
  372.  
  373. You elect to match the object type by setting the MATCH_OBJECTTYPE flag 
  374. in your FIleIOSupport structure.  The object types typically of interest 
  375. are WBTOOL and WBPROJECT.  By selecting one of these types, your 
  376. filename list will consist only of executable files or data files 
  377. respectively (except that all .info drawer names are always displayed).  
  378. If this is confusing, refer to the ROM Kernel manual for a discussion 
  379. of object types.  
  380.  
  381. You can also request to match a Workbench tool type.  By matching tool 
  382. types, you can, for instance, have your file list display only those 
  383. data files that were created by a specific application.  See the section 
  384. entitled "The ToolTypes Array" in the Workbench chapter of the 
  385. ROM Kernel manual for a description of how tool types work.  You elect 
  386. to match tool types by setting the MATCH_TOOLTYPES flag in your 
  387. FileIOSupport structure.  The ToolTypes text that you must supply 
  388. should be written into the ToolTypes[] field of your FileIOSupport 
  389. structure.  
  390.  
  391.  
  392.  
  393. === If You Don't Want Workbench-style Filename Operations ===================
  394.  
  395. If you don't intend on using the Workbench-style pattern matching as
  396. described above, then make sure you comment out the WBENCH_CODE definition.
  397. This will result in a savings of about 500 bytes of code size.
  398.  
  399. If you comment out the WBENCH_CODE definition, then setting the WBENCH_MATCH
  400. flag in your FileIOSupport structure will have no effect.
  401.  
  402.  
  403.  
  404. === FileIOSupport Flags =====================================================
  405.  
  406. GOOD_FILENAMES
  407.     This flag designates whether the filename data contained in the 
  408.     FileIOSupport is valid.  The flag is cleared by the 
  409.     GetFileIOSupport() function, and is usually set by the 
  410.     GetFileIOName() function.  When GetFileIOName() is called, this 
  411.     flag is checked and if it's set then the disk isn't reexamined for 
  412.     file names.  You should clear this flag in your FileIOSupport 
  413.     structures in two instances.  First, when you receive an Intuition 
  414.     IDCMP event of DISKINSERTED you should clear this flag in all of 
  415.     your FileIOSupport structures.  Second, if you have more than 
  416.     one FileIOSupport structure then on return from a call to 
  417.     GetFileIOName() you should check whether your support structure 
  418.     has the DISK_HAS_CHANGED flag set and if so you should clear 
  419.     the DISK_HAS_CHANGED flag in the structure and clear the 
  420.     GOOD_FILENAMES flag in all of your other FileIOSupport structures.  
  421.  
  422.  
  423. USE_VOLUME_NAMES
  424.     When you leave this flag set, the AmigaDOS volume names will 
  425.     be used for the disk names in the requester.  If you clear 
  426.     this flag, the device names will be used instead.  What's a 
  427.     volume name and what's a device name?  Well, if you have your 
  428.     Workbench disk in the Amiga's internal drive, then the volume 
  429.     name of that disk is "Workbench:" and the device name is "DF0:".  
  430.     Which you choose to use is up to you.  Programmers are more 
  431.     familiar with device names.  The typical end-user is more 
  432.     familiar with volume names.  The default is to follow the 
  433.     Workbench convention and use volume names.  
  434.  
  435.  
  436. DISK_HAS_CHANGED
  437.     If the user changes the disk while the FileIO Requester is 
  438.     being displayed, this flag is set in the FileIOSupport 
  439.     structure.  The only time you must pay attention to this 
  440.     flag is when you have multiple FileIOSupport structures.  
  441.     If you find that this flag has been set, you must clear 
  442.     this flag in your FileIOSupport structure and then clear 
  443.     the GOOD_FILENAMES flag in all of your other FileIOSupport 
  444.     structures.  
  445.  
  446.  
  447. DOUBLECLICK_OFF
  448.     Normally, the user can double-click on a filename to select it.  
  449.     You may choose to disable this feature, for instance, 
  450.     when you want the user to be very certain about the 
  451.     filename selection (perhaps if the file is about to 
  452.     be destroyed, or something equally drastic).  
  453.     To disable double-clicking, set the DOUBLECLICK_OFF flag.  
  454.     Then the user will have to explicitly select OK! or type 
  455.     and filename and hit return for the selection to be made.
  456.  
  457.  
  458. WBENCH_MATCH
  459.     You set this flag to specify that you want Workbench-style 
  460.     .info file logic to be used when constructing the filename list.  
  461.     If you set this flag, only directory names and file names that 
  462.     pass the .info file tests will be displayed in the file name 
  463.     list.  See the "Workbench-style Filename Operations" section 
  464.     above for complete information.  This flag is cleared when 
  465.     your FileIOSupport structure is first created.
  466.  
  467.  
  468. MATCH_OBJECTTYPE
  469.     When you set this flag (and the WBENCH_MATCH flag), the 
  470.     DiskObjectType field of your FileIOSupport structure will 
  471.     be compared with the do_Type field of the .info file's 
  472.     DiskObject structure.  If they match, the file will be 
  473.     displayed.  Both the MATCH_TOOLTYPE and the MATCH_OBJECTTYPE 
  474.     flags can be set at the same time.  See the "Workbench-style 
  475.     Filename Operations" section above for complete information.  
  476.  
  477.  
  478. MATCH_TOOLTYPE
  479.     If you set this flag (and the WBENCH_MATCH flag), then 
  480.     Workbench-style ToolType pattern matching will be performed 
  481.     and must be successful before the filename will be included 
  482.     in the list.  You specify your selection of ToolType in the 
  483.     FileIOSupport structure's ToolType[] field.  Both the 
  484.     MATCH_TOOLTYPE and the MATCH_OBJECTTYPE flags can be set at 
  485.     the same time.  See the "Workbench-style Filename Operations" 
  486.     section above for complete information.  
  487.  
  488.  
  489. RENAME_RAMDISK
  490.     This is a flag that exists because of what seems to be a bug 
  491.     in 1.2 AmigaDOS.  For some reason, whenever one attempts to get 
  492.     an AmigaDOS Lock on the volume named "RAM DISK:" a software 
  493.     error occurs.  The problem doesn't necessarily lie in AmigaDOS, 
  494.     but the truth is that the error occurs with little provocation 
  495.     of AmigaDOS (for instance:
  496.         dir "RAM DISK:"
  497.     can and does crash the Amiga).  Until this bug is resolved, 
  498.     the FileIO code provides a work-around by supplying the 
  499.     RENAME_RAMDISK flag.  When the FileIO code is about to get 
  500.     a lock on a volume named "RAM DISK:", if this flag is set 
  501.     then the volume's name is changed internally to "RAM:" which 
  502.     locks successfully and does not crash the machine.
  503.     This solution has a problem:  if the user has given the name 
  504.     "RAM DISK:" to some non-RAM: disk (such as a floppy) then this 
  505.     fix will fail and the floppy named "RAM DISK:" wouldn't be seen.
  506.     This isn't too bad of a problem, because if the user has been 
  507.     silly enough to name a floppy "RAM DISK:" the user is probably 
  508.     experiencing lots of other problems already and this will 
  509.     provide just one more reason why one shouldn't name a floppy 
  510.     "RAM DISK:" don'cha know.
  511.     With the current release of the Suite Book 1, the RENAME_RAMDISK 
  512.     flag is set when your FileIOSupport structure is first created.
  513.  
  514.  
  515.  
  516. === GetFileIOName() is non-reentrant =======================================
  517.  
  518. If your program doesn't create tasks, or if you have multiple tasks 
  519. but only one of your tasks will call GetFileIOName() (which is almost 
  520. always the case), you can ignore the following information.  
  521.  
  522. The GetFileIOName() routine is non-reentrant.  For the sake of memory 
  523. efficiency, it uses global data and variables rather than creating local 
  524. copies of these for each caller.  
  525.  
  526. What this means is that if you have created a program that has more 
  527. than one task, GetFileIOName() cannot be called by more than one task 
  528. at a time.  This is not a problem for the grand majority of programs.  
  529.  
  530. But if you have some application that would require calling this routine 
  531. asynchronously from multiple tasks, you'll have to implement some 
  532. quick semaphore arrangement to avoid collisions.  No big deal, actually.  
  533. See Exec semaphores for everything you need.  
  534.  
  535.  
  536.  
  537.  
  538. === Procedure for Adding the FileIO Requester to Your Program ===============
  539.  
  540. This section presents a step-by-step procedure for incorporating
  541. the FileIO Requester code into your own program.
  542.  
  543.  
  544.  
  545. Copy these FileIO files into your directory (and include them in your 
  546. makefile):
  547.     alerts.c chipdata.c fileio.c filename.c filesupp.c globfio.c 
  548.     opendata.c pointers.c reqsupp.c strings.c volname.c
  549.     fileio.h eglobfio.c
  550.  
  551.  
  552.  
  553. You have to include fileio.h in every file that refers to your
  554. FileIOSupport structure.  
  555.  
  556.     #include "fileio.h"
  557.  
  558.  
  559.  
  560. Are you going to provide your users with Workbench-style .info file
  561. pattern matching?  If so, then go into fileio.h and make sure that 
  562. WBENCH_CODE is defined.  
  563.  
  564.     #define WBENCH_CODE
  565.  
  566. If you're not going to provide Workbench .info file pattern matching, 
  567. verify that WBENCH_CODE isn't defined.  This make the FileIO code
  568. about 500 bytes smaller.
  569.  
  570.     /* #define WBENCH_CODE */
  571.  
  572.  
  573.  
  574. Declare a pointer to a FileIOSupport structure, and then fill that 
  575. pointer with the address of one of the structures.
  576.  
  577.     struct FileIOSupport *FileIOSupp;
  578.  
  579.     FileIOSupp = GetFileIOSupport();
  580.  
  581.  
  582.  
  583. Your NewWindow structure should have the DISKINSERTED flag set along with 
  584. your other IDCMP flags.  Whenever you receive a DISKINSERTED event, you 
  585. should clear the GOOD_FILENAMES flag in every FileIOSupport structure you 
  586. control.  The following code could be added to the case switch where you 
  587. handle IDCMP events.
  588.  
  589.     switch (imessageclass)
  590.         {
  591.         case DISKINSERTED:
  592.             /* You should clear the GOOD_FILENAMES flag 
  593.              * whenever you detect that a new disk was 
  594.              * inserted.
  595.              */
  596.             if (FileIOSupp)
  597.                 ClearFlag(FileIOSupp->Flags, GOOD_FILENAMES);
  598.             break;
  599.         }
  600.  
  601.  
  602.  
  603. When you want to present the FileIO Requester to the user, call 
  604. GetFileIOName().  If this routine returns TRUE, the user did not cancel the
  605. operation.  The following code is an example of presenting the FileIO
  606. Requester to the user and then reacting to the result.
  607.  
  608.     if (FileIOSupp)
  609.         if (GetFileIOName(FileIOSupp, window))
  610.             {
  611.             UBYTE name[128];
  612.  
  613.             BuildFileIOPathname(FileIOSupp, &name[0]);
  614.  
  615.             /* Here do something like read or write the file.
  616.              * If you write the file, you should call 
  617.              * AddFileIOName() if you've created a new file 
  618.              * or if you don't want to bother checking 
  619.              * whether or not it was a newly-created file.
  620.              */
  621.             if (writefile) AddFileIOName(FileIOSupp, &name[0]);
  622.             }
  623.  
  624.  
  625.  
  626.  
  627. Finally, when you're done with your FileIOSupport structure (usually when 
  628. you're program is exiting), you can free up the structure and its resources 
  629. with a simple call to ReleaseFileIO(), like this:
  630.  
  631.     if (FileIOSupp) ReleaseFileIO(FileIOSupp);
  632.  
  633.  
  634.  
  635.  
  636. =============================================================================
  637. === DEMO PROGRAM NOTES ======================================================
  638. =============================================================================
  639.  
  640. This section briefly describes the demo program that drives some of 
  641. the FileIO Requester's features.  
  642.  
  643. If you invoke the program without a second argument, a window will be 
  644. opened in the Workbench screen.  If you invoke the program with any 
  645. second argument, a low-res screen will be opened for the requester window.  
  646.  
  647. The program uses two FileIOSupport structures to demonstrate the 
  648. techniques that you should use when managing multiple FileIOSupports.  
  649. These techniques include processing DISKINSERTED events and discovering 
  650. on return from GetFileIOName() that the DISK_HAS_CHANGED flag is set.  
  651.  
  652. The first support structure, fileio1, is used in its vanilla state 
  653. as created by GetFileIOSupport().  The other support structure, fileio2, 
  654. is initialized to do Workbench-style .info file handling where the 
  655. filename list will consist of only .info objects of type WBPROJECT.  
  656.  
  657. Also, every time you insert a disk, the USE_VOLUME_NAMES flag in the 
  658. support structures is toggled, so that first you see volume names and 
  659. then you see device names.  This is for demonstration only; it's not 
  660. suggested that you use this technique in a real program.  
  661.  
  662. Finally, when you do any of the selection techniques where you accept 
  663. your selection, the pathname to your selection is displayed in an 
  664. autorequester.  If you choose CANCEL to end the requester, nothing happens.  
  665.  
  666. To stop the program, click in the window close gadget.  
  667.  
  668.  
  669.  
  670.  
  671.  
  672. =============================================================================
  673. === TECHNICAL REFERENCE =====================================================
  674. =============================================================================
  675.  
  676. This section gives you a brief outline of the FileIO software system files, 
  677. plus some scanty supplementary information.  
  678. Please refer to the source code itself.  The routines are commented 
  679. and, hopefully, reasonably laid out.  
  680.  
  681.  
  682. The FileIO files include:
  683.  
  684.     alerts.c
  685.         Autorequester alert routines for emergency
  686.         and shortcut communications
  687.  
  688.     chipdata.c
  689.         Data for the Open requester that must be in chip memory
  690.  
  691.     eglobfio.c 
  692.         External global variable declarations
  693.  
  694.     fileio.c
  695.         FileIO interface routines:  GetFileIOSupport(), 
  696.         GetFileIOName(), BuildFileIOPathname(), AddFileIOName(), 
  697.         and ReleaseFileIO()
  698.  
  699.     fileio.h 
  700.         The FileIO structure and constants definitions
  701.  
  702.     filename.c
  703.         Routines that build the filename list
  704.  
  705.     filesupp.c
  706.         Routines that create and manage the Open Requester
  707.  
  708.     globfio.c
  709.         Global variable declarations
  710.  
  711.     main.c
  712.         Demonstration program
  713.  
  714.     opendata.c
  715.         Open Requester declarations
  716.  
  717.     pointers.c
  718.         Pointer routines of the Amiga Programmer's Suite
  719.  
  720.     reqsupp.c
  721.         DoRequest() routine of the Amiga Programmer's Suite
  722.  
  723.     strings.c
  724.         RJ's general crude but illustrative string manipulation 
  725.         routines
  726.  
  727.     volname.c 
  728.         Routines that build the volume list
  729.  
  730.  
  731.  
  732.  
  733.  
  734. === USING THE AMIGA PROGRAMMER'S SUITE ======================================
  735.  
  736. The Amiga Programmer's Suite Book 1 is copyrighted but freely distributable.
  737. All copyright notices and all file headers must be retained intact.
  738. The Amiga Programmer's Suite Book 1 may be compiled and assembled, and the 
  739. resultant object code may be included in any software product.  However, no 
  740. portion of the source listings or documentation of the Amiga Programmer's 
  741. Suite Book 1 may be distributed or sold for profit or in a for-profit 
  742. product without the written authorization of the author, RJ Mical.
  743.  
  744. If you use the Amiga Programmer's Suite, I wouldn't mind if you gave me 
  745. some mention somewhere.
  746. Good luck!  Program hard, program well.    -RJ Mical
  747.  
  748.  
  749.  
  750.  
  751. === APPENDIX A:  FileIO Function Calls ======================================
  752.  
  753. CONTENTS:
  754.    AddFileIOName()
  755.    BuildFileIOPathname()
  756.    GetFileIOSupport()
  757.    GetFileIOName()
  758.    ReleaseFileIO()
  759.  
  760.  
  761.  
  762.  
  763.  
  764. *** AddFileIOName() ******************************************************
  765.  
  766. NAME
  767.     AddFileIOName  --  Add a file name to the names in a FileIOSupport
  768.  
  769.  
  770. SYNOPSIS
  771.     AddFileIOName(FileIOSupport, FileName);
  772.  
  773.  
  774. FUNCTION
  775.     This routine adds a file name to the list of file names currently 
  776.     in the specified FileIOSupport structure.  The next time the 
  777.     FileIOSupport structure is used for a call to GetFileIOName(), the 
  778.     new file name will apppear alphabetized in with the other file names.  
  779.     
  780.     This routine will most often be used after a call to GetFileIOName() 
  781.     or some other routine where the user is allowed to specify the name 
  782.     of a file to be opened for output.  If the file is opened 
  783.     successfully, this routine will make sure that the name of the file 
  784.     is in the FileIOSupport structure.  This is important if the output 
  785.     file has been newly created; otherwise, without calling this 
  786.     routine, the next time the FileIOSupport structure is used the new 
  787.     file name would not appear even though the file exists.  If the name 
  788.     is already in the list when you call AddFileIOName() then nothing 
  789.     happens.  This allows you to call AddFileIOName() without worrying 
  790.     about duplicate name redundancy.
  791.     
  792.     Here's a typical sequence of events leading up to a call to 
  793.     AddFileIOName():
  794.     
  795.         First, get a FileIOSupport structure:
  796.             fileio = GetFileIOSupport(...);
  797.     
  798.         When the user wants to write data, use GetFileIOName()
  799.         to provide a convenient and consistent interface to
  800.         the filesystem:
  801.             goodfile = GetFileIOName(...);
  802.     
  803.         If the user has selected a name for output (in this example,
  804.         goodfile will equal TRUE if the user selected a name), then
  805.         open the file (possibly creating it) and then call 
  806.         AddFileIOName() to make sure the name is in the FileIOSupport
  807.         structure's list:
  808.             if (goodfile)
  809.                 {
  810.                 UBYTE filename[80];
  811.                 
  812.                 BuildFileIOPathname(fileio, &filename[0]);
  813.                 ... open filename, write it, close it ...
  814.                 if (filename opened successfully)
  815.                     AddFileIOName(fileio, &filename[0]);
  816.                 }
  817.  
  818.  
  819. INPUTS
  820.     FileIOSupport = the address of a FileIOSupport structure
  821.     FileName = the address of null-terminated text that is
  822.         either a simple file name or a valid AmigaDOS pathname.
  823.  
  824.  
  825. RESULT
  826.     None
  827.  
  828.  
  829. SEE ALSO
  830.     GetFileIOName()
  831.     GetFileIOSupport()
  832.  
  833.  
  834.  
  835.  
  836.  
  837. *** BuildFileIOPathname() ************************************************
  838.  
  839. NAME
  840.     BuildFileIOPathname  --  Build a file pathname using a FileIO struct
  841.  
  842.  
  843. SYNOPSIS
  844.     BuildFileIOPathname(FileIOSupport, Buffer);
  845.  
  846.  
  847. FUNCTION
  848.     Builds the text for a pathname using the FileName[], DrawerName[] and
  849.     DiskName[] fields of the specified FileIOSupport structure
  850.     after the support structure has been used in a successful call
  851.     to GetFileIOName().  Writes the text into the Buffer.
  852.  
  853.  
  854. INPUTS
  855.     FileIOSupport = the address of a FileIOSupport structure
  856.  
  857.     Buffer = address of the buffer to receive the file pathname
  858.  
  859.  
  860. RESULT
  861.     None
  862.  
  863.  
  864. SEE ALSO
  865.     GetFileIOName()
  866.  
  867.  
  868.  
  869.  
  870.  
  871. *** GetFileIOSupport() ***************************************************
  872.  
  873. NAME
  874.     GetFileIO  --  Allocate and initialize a FileIOSupport structure
  875.  
  876.  
  877. SYNOPSIS
  878.     struct FileIOSupport *GetFileIOSupport();
  879.  
  880.  
  881. FUNCTION
  882.     Allocates and initializes a FileIOSupport structure for use with
  883.     calls to GetFileIOName().
  884.  
  885.     You may want to further initialize the structure before calling
  886.     GetFileIOName().  Refer to the FileIO documentation for more
  887.     information.
  888.  
  889.     When you're done with the structure, call ReleaseFileIO().
  890.  
  891.  
  892. INPUTS
  893.     None
  894.  
  895.  
  896. RESULT
  897.     If all goes well, returns the address of a FileIOSupport structure.
  898.     If anything goes wrong (usually out of memory), returns NULL.
  899.  
  900.  
  901. EXAMPLE
  902.     struct FileIOSupport *fileio;
  903.     fileio = GetFileIOSupport();
  904.     GetFileIOName(fileio, window);
  905.     ReleaseFileIO(fileio);
  906.  
  907.  
  908. BUGS
  909.     None known
  910.  
  911.  
  912. SEE ALSO
  913.     GetFileIOName(), ReleaseFileIO()
  914.  
  915.  
  916.  
  917.  
  918.  
  919. *** GetFileIOName() ******************************************************
  920.  
  921. NAME
  922.     GetFileIOName  --  Gets a file name for input/output from the user
  923.  
  924.  
  925. SYNOPSIS
  926.     BOOL GetFileIOName(FileIO, Window);
  927.  
  928.  
  929. FUNCTION
  930.     This routine creates a filename requester which allows the user
  931.     to browse through the AmigaDOS filesystem and select one of
  932.     the filenames found there.
  933.  
  934.     The FileIO argument is a pointer to a FileIOSupport structure,
  935.     which is allocated and initialized for you via a call to 
  936.     GetFileIOSupport().
  937.     You may preset the FileIO parameters before calling this routine, 
  938.     or you may leave them set at their default values.  See the FileIO
  939.     documentation for complete details.
  940.  
  941.     The Window argument is the pointer to the window structure returned
  942.     by a call to Intuition's OpenWindow() function.  As this routine
  943.     opens a requester and requesters open in windows, you must have
  944.     already opened a window before calling this routine, even if it's
  945.     a window opened for no other purpose than to call this routine.
  946.  
  947.     This routine returns a BOOL value of TRUE or FALSE, depending on
  948.     whether the user chose to accept or cancel the filename selection 
  949.     operation.  If TRUE, the filename selected by the user can be
  950.     found in the FileIO structure FileName[] field.  This filename
  951.     will have all leading and trailing blanks removed (in case the
  952.     user typed in a filename with extraneous spaces).  Likewise,
  953.     the pathname to the disk and drawer can be found in the text
  954.     fields DiskName[] and DrawerName[].  You can construct 
  955.     the pathname using these text strings.  Also, you can call 
  956.     BuildFileIOPathname() to build the pathname automatically.
  957.  
  958.     There's a *lot* more to be said about this function.  Please 
  959.     read the documentation.
  960.  
  961.     NOTE:  This routine is not re-entrant.  What this means 
  962.     is that if you have created a program that has more than one task,
  963.     this routine cannot be called by more than one task at a time.
  964.     This is not a problem for the grand majority of programs.
  965.     But if you have some application that would require calling this 
  966.     routine asynchronously from multiple tasks, you'll have to 
  967.     implement some quick semaphore arrangement to avoid collisions.
  968.     No big deal, actually.  See Exec semaphores for everything you need.
  969.  
  970.  
  971. INPUTS
  972.     FileIO = pointer to a FileIOSupport structure, as allocated
  973.         via a call to GetFileIOSupport()
  974.  
  975.     Window = pointer to a Window structure, as created via a call
  976.         to Intuition's OpenWindow()
  977.  
  978.  
  979. RESULT
  980.     TRUE if the user decided that the filename selection was successful,
  981.     FALSE if the user chose to cancel the operation
  982.  
  983.  
  984. EXAMPLE
  985.     if (GetFileIOName(fileio, window))
  986.         ProcessFileName(&fileio->FileName[0]);
  987.  
  988.  
  989. BUGS
  990.     None known, though there could be some, and the disk selection
  991.     subsystem logic is not perfectly polished (though it's believed 
  992.     to be bug-free).
  993.  
  994.  
  995. SEE ALSO
  996.     BuildFileIOPathname(), GetFileIOSupport(), ReleaseFileIO()
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002. *** ReleaseFileIO() ******************************************************
  1003.  
  1004. NAME
  1005.     ReleaseFileIO  --  Release the FileIO structure and all local memory
  1006.  
  1007.  
  1008. SYNOPSIS
  1009.     ReleaseFileIO(FileIO);
  1010.  
  1011.  
  1012. FUNCTION
  1013.     Releases the FileIO structure by freeing all local memory attached
  1014.     to the structure and then freeing the structure itself.
  1015.  
  1016.  
  1017. INPUTS
  1018.     FileIO = the address of a FileIO structure
  1019.  
  1020.  
  1021. RESULT
  1022.     None
  1023.  
  1024.  
  1025. SEE ALSO
  1026.     GetFileIOSupport()
  1027.  
  1028.